package cn.manjuu.touhou.activity;

import cn.manjuu.touhou.APP;
import cn.manjuu.touhou.R;
import cn.manjuu.touhou.engine.DramaEngine;
import cn.manjuu.touhou.util.Looger;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 用来进行剧情对话的Activity
 * 
 * @author sjj
 * @since 2013.5.24
 * 
 */
public class DramaActivity extends Activity implements OnClickListener {

	private RelativeLayout rl_drama;
	private ImageView iv_drama_character;
	private TextView tv_drama_content;
	private String mTheme;

	public ImageView getIv_drama_character() {
		return iv_drama_character;
	}

	public TextView getTv_drama_content() {
		return tv_drama_content;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.drama);
		findView();
		registerListener();

		init();
	}

	private void init() {
		mTheme = getIntent().getStringExtra("theme");
		Looger.i(APP.DramaActivity, "theme: " + mTheme);
		DramaEngine.getInstance().setActivity(this);
		DramaEngine.getInstance().initTheme(mTheme);
		boolean next = DramaEngine.getInstance().next();
		if (!next) {
			finish();
			overridePendingTransition(R.anim.alpha_enter, R.anim.alpha_exit);
		}
	}

	private void findView() {
		rl_drama = (RelativeLayout) findViewById(R.id.rl_drama);
		tv_drama_content = (TextView) findViewById(R.id.tv_drama_content);
		iv_drama_character = (ImageView) findViewById(R.id.iv_drama_character);
	}

	private void registerListener() {
		// TODO Auto-generated method stub
		rl_drama.setOnClickListener(this);
	}

	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		Looger.i(APP.DramaActivity, "keyCode: " + keyCode);
		switch (keyCode) {
		case KeyEvent.KEYCODE_BACK:

			break;
		case KeyEvent.KEYCODE_MENU:

			break;
		}
		return super.onKeyUp(keyCode, event);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.rl_drama:
			boolean next = DramaEngine.getInstance().next();
			if (!next) {
				finish();
				overridePendingTransition(R.anim.alpha_enter, R.anim.alpha_exit);
			}
			break;
		}
	}
}
